{{ define "/admin/role/add" }}

{{ template "public/header" }}

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:left" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>角色名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    1到20个字符
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label">
                    <span class="x-red">*</span>角色描述
                </label>
                <div class="layui-input-block">
                    <textarea placeholder="输入内容只能1到150个字符" id="desc" name="desc" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label">
                    <span class="x-red">*</span>超级管理员
                </label>
                <div class="layui-input-block">
                    <input type="radio" name="super" value="0" title="否" checked>
                    <input type="radio" name="super" value="1" title="是">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">
                    添加
                </button>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form
        var layer = layui.layer
        //监听提交
        form.on('submit(add)', function (obj) {
            $.ajax({
                type: "post",
                url: obj.form.action,
                data: obj.field,
                dataType: "json",
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 2,
                            time: 2000//2秒关闭（如果不配置，默认是3秒）
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</html>
{{ end }}